/**
 * 入库管理 - 查询入库退货记录
 * Created by zengtao on 2017/8/28.
 */
define(["jquery", "artTemplate","common"], function ($, art,common) {
	var url = common.kcUrl(); 
	return function (begin_date,end_date,key_word) {
		//请求入库退货历史记录
		var getDataBegin = layer.load(4, {time: 6*1000});
		$("#rkgl_thwpxx_ul_svb").empty();
		$("#wpxx_thdh").text("");
		$.ajax({
			type: "POST",
			data:{
				type:1,
				begindate:begin_date || "",
				enddate:end_date || "",
				searchkey:key_word || ""
			},
			url: url + "stock/inbillList.shtml",
			success :function(res){
				layer.close(getDataBegin); 
				var result = eval('(' + res.result + ')');
				if(result.length == 0){
					$("#rk_tuihuo_list").empty().append("<li class='list_empty'><span>暂无数据</span></li>");
					return
				}
				var rkList = art.render($("#tpl_rkgl_rkth_listl").html(), {
					result: result   
				});					
				var $rkList = $(rkList);
				$("#rk_tuihuo_list").empty();
				$("#rk_tuihuo_list").append($rkList);
				setPaddingR("#rk_tuihuo_list",".th_title_pr");
				
				//左侧列表点击切换样式
				$('#rk_tuihuo_list').off("click").on("click",".list_jl_view_1503",function(){
					$(this).siblings().removeClass("list_active").end().addClass("list_active");
					var getDataBegin = layer.load(4, {time: 6*1000});
					
					//根据入库退货单号请求入库详细信息
					var sk_in_bill = $(this).find(".sk_in_bill_ipt").val();
					$("#wpxx_thdh").text(sk_in_bill);
					$.ajax({
						type: "GET",
						url: url + "stock/instockList.shtml?type=1&bill="+sk_in_bill,
						success: function(res){
							layer.close(getDataBegin);
							var result = eval('(' + res.result + ')');
							//console.log("入库单号：",result);
							var rkList = art.render($("#tpl_rkgl_rkth_wplistl").html(), {
								result: result   
							});					
							var $rkList = $(rkList);
							$("#rkgl_thwpxx_ul_svb").empty();
							$("#rkgl_thwpxx_ul_svb").append($rkList);
							setPaddingR("#rkgl_thwpxx_ul_svb",".thwp_title_pr");

							//点击每项物品信息改变样式及选中状态
							$("#rkgl_thwpxx_ul_svb > li").on("click",function(){
								//物品信息列表li标签样式								
								$(this).toggleClass("list_active");
							});
						}
					});
				});
				
				//入库退货记录 - 默认显示第一条入库退货单号的退货详细
				if($('#rk_tuihuo_list .list_jl_view_1503').eq(0)){
					$('#rk_tuihuo_list .list_jl_view_1503').eq(0).trigger("click");
				}
			}
		});
	};
});


